import logging
import subprocess
from django.conf import settings
from celery import shared_task


@shared_task
def deploy(endpoints):
    logging.getLogger().info('正在重启系统')
    if 'frontend' in endpoints:
        deploy_frontend()
    if 'backend' in endpoints:
        deploy_backend()


def deploy_frontend():
    logging.getLogger().info('正在重启WEX前端')
    subprocess.run(settings.FRONTEND_DEPLOY_COMMAND, check=True, cwd='.')


def deploy_backend():
    logging.getLogger().info('正在重启WEX后端')
    subprocess.run(settings.BACKEND_DEPLOY_COMMAND, check=True, cwd='.')
